<?php
namespace app\index\job;

use think\Exception;
use think\Queue;
use think\queue\Job;

class MultiTask
{
    /**
     * 多模块
     */
    public function multiTask()
    {
        $taskType = $_GET['taskType'];
        switch ($taskType) {
            case "taskOne":
                $jobHandleClassName = "app\api\job\MultiTask@taskOne";
                $jobQueueName = "taskOneQueue";
                $jobData = ['ts' => time(), 'bizId' => uniqid(), 'data' => $_GET];
                break;
            case "taskTwo":
                $jobHandleClassName = "app\api\job\MultiTask@taskTwo";
                $jobQueueName = "taskTwoQueue";
                $jobData = ['ts' => time(), 'bizId' => uniqid(), 'data' => $_GET];
                break;
            default:
                break;
        }
        $isPushed = Queue::push($jobHandleClassName, $jobData, $jobQueueName);
        if ($isPushed !== false) {
            echo date('Y-m-d H:i:s') . "the $taskType of multiTask job has been pushed to $jobQueueName";
        } else {
            throw new Exception("push a new $taskType of multiTask job Failed!");
        }
    }
}
